<?php
namespace DuxCms\Controller;
use Admin\Controller\AdminController;
/**
 * 栏目管理
 */
class AdminAdController extends AdminController
{
	/**
	 * 当前模块参数
	 */
	protected function _infoModule(){
		return array(
				'info'  => array(
						'name' => '广告管理',
						'description' => '管理网站的所有广告',
				),
				'menu' => array(
						array(
								'name' => '广告列表',
								'url' => U('index'),
								'icon' => 'list',
						),
	
				),
				'add' => array(
						array(
								'name' => '添加广告',
								'url' => U('add'),
								'icon' => 'plus',
						),
				)
		);
	}
    /**
     * 列表
     */
    public function index()
    {
        $breadCrumb = array('广告列表' => U());
        $limit = $this->getPageLimit($count,30);
        $this->assign('breadCrumb', $breadCrumb);
        $this->assign('list', D('Ad')->loadList('',$limit));
        $this->assign('page',$this->getPageShow());
        $this->adminDisplay();
    }
    /**
     * 添加
     */
    public function add(){
    	if(!IS_POST){
    		$breadCrumb = array('广告列表'=>U('index'),'广告添加'=>U());
    		$this->assign('breadCrumb',$breadCrumb);
    		$this->assign('name','添加');
    		$this->assign('positionList',D('DuxCms/Position')->loadList());
    		$this->assign('default_config',current_config());
    		$this->adminDisplay('info');
    	}else{
    		if(D('Ad')->saveData('add')){
    			$this->success('广告添加成功！');
    		}else{
    			$msg = D('Ad')->getError();
    			if(empty($msg)){
    				$this->error('广告添加失败');
    			}else{
    				$this->error($msg);
    			}
    		}
    	}
    }
    /**
     * 修改
     */
    public function edit(){
    	if(!IS_POST){
    		$id = I('get.id','','intval');
    		if(empty($id)){
    			$this->error('参数不能为空！');
    		}
    		//获取记录
    		$model = D('Ad');
    		$info = $model->getInfo($id);
    		if(!$info){
    			$this->error($model->getError());
    		}
    		$breadCrumb = array('广告列表'=>U('index'),'广告修改'=>U('',array('id'=>$id)));
    		$this->assign('breadCrumb',$breadCrumb);
    		$this->assign('name','修改');
    		$this->assign('info',$info);
    		$this->assign('positionList',D('DuxCms/Position')->loadList());
    		$this->assign('default_config',current_config());
    		$this->adminDisplay('info');
    	}else{
    		if(D('Ad')->saveData('edit')){
    			$this->success('文章修改成功！');
    		}else{
    			$msg = D('Ad')->getError();
    			if(empty($msg)){
    				$this->error('文章修改失败');
    			}else{
    				$this->error($msg);
    			}
    		}
    	}
    }
    /**
     * 删除
     */
    public function del(){
    	$id = I('post.data',0,'intval');
    	if(empty($id)){
    		$this->error('参数不能为空！');
    	}
    	if(D('Ad')->delData($id)){
    		$this->success('文章删除成功！');
    	}else{
    		$this->error('文章删除失败！');
    	}
    }
}

